<?php

/* @project : Template
 * @auther  : 青云
 * @date    : 2018/1/10
 * @desc    : 用户控制器
 */

namespace app\admin\controller;

use think\Request;

use app\common\model\Notify as NotifyModel;
use app\common\model\Tag as TagModel;
use app\common\model\Excel;

class Notify extends Base
{

    function index(Request $request)
    {

        cookie('current_node', null);

        $request->eq_type        = 'user';
        $request->eq_receiver_id = get_user_id();

        return $this->_index($request);
    }

    function mark_is_read(Request $request)
    {
        $id_list = rotate($request->data, 'id');

        $notify_model = new NotifyModel();

        $ret = $notify_model->markIsRead($id_list);

        if ($ret !== false) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_error('操作失败');
        }
    }

    function mark_all_is_read()
    {
        $user_id = get_user_id();

        $notify_model = new NotifyModel();

        $ret = $notify_model->markIsReadByReceiverId($user_id, 'user');

        if ($ret !== false) {
            return $this->api_success('操作成功');
        } else {
            return $this->api_error('操作失败');
        }
    }

    function del(Request $request)
    {
        $id_list = rotate($request->data, 'id');

        $notify_model = new NotifyModel();
        $ret          = $notify_model->del($id_list);
        if ($ret) {
            return $this->api_success('删除成功');
        } else {
            return $this->api_error('删除失败');
        }
    }

    function del_all(Request $request)
    {
        $notify_model = new NotifyModel();
        $ret          = $notify_model->delByReceiverId(get_user_id(), 'user');
        if ($ret) {
            return $this->api_success('删除成功');
        } else {
            return $this->api_error('删除失败');
        }
    }

}
